using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace SampleDataTools
{
    public partial class SelectForm : DevComponents.DotNetBar.OfficeForm
    {
        public SelectForm()
        {
            InitializeComponent();
        }

        private Control[] ControlData;
        public void SetData(Control[] controls)
        {
            if (controls != null)
            {
                ControlData = controls;
                listBoxAdv1.DataSource = ControlData;
                listBoxAdv1.DisplayMember = "Name";
            }
        }

        public Control[] GetCheckedData()
        {
            var items = listBoxAdv1.CheckedItems;
            List<Control> res = new List<Control>();
            foreach (var item in items)
            {
                DevComponents.DotNetBar.ItemBindingData data = item.Tag as DevComponents.DotNetBar.ItemBindingData;
                if (data != null)
                {
                    res.Add(ControlData[data.BindingIndex]);
                }
            }
            return res.ToArray();
        }

        private void SelectAllCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (ControlData != null)
            {
                for (int i = 0; i < ControlData.Length; ++i)
                {
                    listBoxAdv1.SetItemCheckState(i, SelectAllCheckBox.CheckState);
                }
            }
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}